/**
 * 将url中的gitcode.com替换为当前域名
 * @param url 
 * @returns 替换后的url
 */
export const transformUrl = (url: string) => {
  try {
    const requestURL = useRequestURL()
    const host = requestURL?.host|| ''
    // 仅替换主域名，保留子域名
    const baseDomain = host.split('.').slice(-2).join('.')
    return url?.replace(/gitcode\.com|gitcode\.net/g, baseDomain)
  }
  catch (error) {
    return url
  }
};

/**
 * 获取当前主域名
 */
export const getDomain = () => {
  const requestURL = useRequestURL()
  const host = requestURL?.host || ''
  const baseDomain = host.split('.').slice(-2).join('.')
  return baseDomain
}
